#include "lcd.h"

static unsigned int fb_base;
static int xres, yres, bpp;

void fb_get_lcd_params(void)
{
	get_lcd_params(&fb_base, &xres, &yres, &bpp);
}

/* 0x00RRGGBB */
unsigned short covert32bppto16bpp(unsigned int rgb)
{
	int r = (rgb>>16) & 0xff;
	int g = (rgb>>8) & 0xff;
	int b = rgb & 0xff;

	r = r >> 3;
	g = g >> 2;
	b = b >> 3;
	
	return ((r<<11) | (g<<5) | (b));
}

void fb_put_pixel(int x, int y, unsigned int color)
{
	unsigned char *p = fb_base + (xres * bpp/8)*y + x*bpp/8;
	unsigned short *pw = (unsigned short *)p;
	unsigned int *pdw = (unsigned int *)p;

	switch(bpp)
	{
		case 8:
			*p = color;
			break;
		case 16:
			*pw = covert32bppto16bpp(color);
			break;
		case 32:
			*pdw = color;
			break;
	}
}



